package com.pinecone.controller;

import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pinecone.entity.SysCloudConfigEntity;
import com.pinecone.service.SysCloudConfigService;
import com.pinecone.common.utils.PageUtils;
import com.pinecone.common.utils.Query;
import com.pinecone.common.utils.R;




/**
 * 第三方云服务安全配置
 * 
 * @author hushangjie
 * @email 979783618@qq.com
 * @date 2017-09-27 21:17:58
 */
@RestController
@RequestMapping("syscloudconfig")
public class SysCloudConfigController {
	@Autowired
	private SysCloudConfigService sysCloudConfigService;
	
	/**
	 * 列表
	 */
	@GetMapping("")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		if (params.get("page") != null && params.get("limit")!= null){
			List<SysCloudConfigEntity> sysCloudConfigList = sysCloudConfigService.queryList(query);
			int total = sysCloudConfigService.queryTotal(query);
			
			PageUtils pageUtil = new PageUtils(sysCloudConfigList, total, query.getLimit(), query.getPage());
			
			return R.ok().put("page", pageUtil);
		}else{
			List<SysCloudConfigEntity> sysCloudConfigList = sysCloudConfigService.queryList(query);
			return R.ok().put("list", sysCloudConfigList);
		}
		
	}
	
	
	/**
	 * 信息
	 */
	@GetMapping("/{serviceConfigId}")
	public R info(@PathVariable("serviceConfigId") Integer serviceConfigId){
		SysCloudConfigEntity sysCloudConfig = sysCloudConfigService.queryObject(serviceConfigId);
		
		return R.ok().put("sysCloudConfig", sysCloudConfig);
	}
	
	/**
	 * 保存
	 */
	@PostMapping("")
	public R save(@RequestBody SysCloudConfigEntity sysCloudConfig){
		sysCloudConfigService.save(sysCloudConfig);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@PutMapping("")
	public R update(@RequestBody SysCloudConfigEntity sysCloudConfig){
		sysCloudConfigService.update(sysCloudConfig);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@DeleteMapping("")
	public R delete(@RequestBody Integer[] serviceConfigIds){
		sysCloudConfigService.deleteBatch(serviceConfigIds);
		
		return R.ok();
	}
	
}
